SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[campos]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[campos](
	[idcampo] [int] IDENTITY(1,1) NOT NULL,
	[nome] [varchar](45) NULL,
	[consulta] [varchar](1500) NULL,
	[tipo_campo_banco] [int] NOT NULL,
	[tipo_campo_interface] [int] NOT NULL,
	[tipo_operador] [int] NOT NULL,
	[entidades_identidade] [int] NOT NULL,
 CONSTRAINT [PK_campos] PRIMARY KEY CLUSTERED 
(
	[idcampo] ASC
)WITH (PAD_INDEX  = OFF, IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[entidades]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[entidades](
	[identidade] [int] IDENTITY(1,1) NOT NULL,
	[nome_entidade] [varchar](45) NOT NULL,
 CONSTRAINT [PK_entidades] PRIMARY KEY CLUSTERED 
(
	[identidade] ASC
)WITH (PAD_INDEX  = OFF, IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[filtro]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[filtro](
	[idfiltro] [int] IDENTITY(1,1) NOT NULL,
	[label] [varchar](45) NOT NULL,
	[negar] [smallint] NOT NULL,
 CONSTRAINT [PK_filtro] PRIMARY KEY CLUSTERED 
(
	[idfiltro] ASC
)WITH (PAD_INDEX  = OFF, IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[filtro_has_campos]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[filtro_has_campos](
	[filtro_idfiltro] [int] NOT NULL,
	[campos_idcampo] [int] NOT NULL,
 CONSTRAINT [PK_filtro_has_campos] PRIMARY KEY CLUSTERED 
(
	[filtro_idfiltro] ASC,
	[campos_idcampo] ASC
)WITH (PAD_INDEX  = OFF, IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[pesquisa]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[pesquisa](
	[idpesquisa] [int] IDENTITY(1,1) NOT NULL,
	[descricao] [varchar](45) NULL,
	[ordem_pesquisa] [varchar](45) NULL,
 CONSTRAINT [PK_pesquisa] PRIMARY KEY CLUSTERED 
(
	[idpesquisa] ASC
)WITH (PAD_INDEX  = OFF, IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[pesquisa_has_filtro]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[pesquisa_has_filtro](
	[pesquisa_idpesquisa] [int] NOT NULL,
	[filtro_idfiltro] [int] NOT NULL,
 CONSTRAINT [PK_pesquisa_has_filtro] PRIMARY KEY CLUSTERED 
(
	[pesquisa_idpesquisa] ASC,
	[filtro_idfiltro] ASC
)WITH (PAD_INDEX  = OFF, IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
END
